<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2018/3/28
  Time: 11:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String realPath = request.getServletContext().getRealPath("/");
  String newPath = realPath.replace('\\', '/');
%>

<div id="page-content">
  <div class="row">
    <div class="col-lg-12">
      <div class="panel">
        <div class="panel-heading">
          <h3 class="panel-title">数据导入导出</h3>
        </div>

        <div class="panel-body">
          <form class="form-horizontal" id="export_form" method="post">
            <input name="filepath" id="filepath" type="hidden" value="" />

            <div class="form-group">
              <label class="col-md-2 control-label">请选择人员类型<i class="fa fa-asterisk txt-color-red"></i></label>
              <div class="col-md-6">
                <select name="userType" id="userType" class="form-control">
                  <option value="">请选择</option>
                  <option value="person">书记</option>
                  <option value="director">主任</option>
                </select>
              </div>
            </div>

            <div class="form-group">
              <label class="col-md-2 control-label">请选择街道<i class="fa fa-asterisk txt-color-red"></i></label>
              <div class="col-md-6">
                <select name="streetId" id="streetId" class="form-control">
                  <option value="">请选择</option>
                  <c:forEach items="${streetList}" var="item" varStatus="index">
                    <option value="${item.id}" <c:if test="${person.street.id==item.id}">selected</c:if> >${item.name}</option>
                  </c:forEach>
                </select>
              </div>
            </div>

          </form>
        </div>

        <div class="panel-footer">
          <a class="btn btn-success" id="btn-submit" href="javascript:void(0)">
            <i class="fa fa-lg fa-arrow-down"></i> 开始导出
          </a>
        </div>

      </div>
    </div>
  </div>
</div>

<script>

  $(function(){
    fn_dateOut_input_validate();
  });

  $("#userType").select2({
    placeholder: "请选择人员类型",
    allowClear: true
  });

  $("#streetId").select2({
    placeholder: "请选择街道",
    allowClear: true
  });

  function fn_dateOut_input_validate(){
    __init_validate('export_form', {
      rules : {
        userType : {
          required : true
        },
        streetId : {
          required : true
        }
      },
      messages : {
        userType : {
          required : "请选择人员类型"
        },
        streetId : {
          required : "请选择街道"
        }
      }
    });
  }


  $("#userType").change(function(){
    if($("#userType option:selected").val()=="person"){
      $("#export_form").attr("action","<%=path%>/com/dataUpdate/export_sj");
    }else if($("#userType option:selected").val()=="director"){
      $("#export_form").attr("action","<%=path%>/com/dataUpdate/export_zr");
    }else{
      $("#export_form").attr("action","");
    }
  });

  $("#btn-submit").click(function(){
    if (!$('#export_form').valid()) {
      __toastr_error("请检查基本信息");
      return false;
    }

    var url = "";
    if("person"==$("#userType option:selected").val()){
      url = "<%=path%>/com/dataUpdate/export_sj";
    }else if("director"==$("#userType option:selected").val()){
      url = "<%=path%>/com/dataUpdate/export_zr";
    }else{
      __toastr_error("没有获取到人员类型");
      return false;
    }
    __confirm_dialog("提示：","确定导出"+$("#userType option:selected").text()+"-"+$("#streetId option:selected").text()+"?",function(){
      $("#export_form #filepath").val("<%=newPath%>/file/"+encodeURIComponent("sj_data.xls"));
//      __form_save("export_form", url,function(data){
//
//      });
      $("#export_form").submit();
    });
  });

</script>